/**
 * 新增参数配置
 * @param url
 * @param formId
 */
function newParamConf(url,formId){
    crmSysParamForm.channel = {channelState:1};
    crmSysParamForm.warranty = {warrantyState:1};
    crmSysParamForm.customerLevel = {levelState:1};
    crmSysParamForm.insurance = {insuranceState:1};
    crmSysParamForm.mortgage = {mortgageState:1};
    layer.open({
        type: 1,
        title:'新增参数',
        area: ['740px', '400px'],
        fixed: false, //不固定
        maxmin: true,
        content: $('#addParamForm'),
        btn:['确定','取消'],
        yes:function(){
            // var formData = $('#addBuyForm').serialize();
            var requiredCode = true;
            $("#" + formId).find('input[required]').each(function(index){
                if($("#" + formId).find('input[required]').eq(index).val() == ''){
                    layer.msg('请输入必填项！');
                    requiredCode = false;
                    return false;
                }
            });
            // return requiredCode;
            if (requiredCode) {
                $.ajax({
                    type: "get",      //data 传送数据类型。post 传递
                    contentType:"application/json",
                    dataType: 'json',  // 返回数据的数据类型json
                    url: crmUrl + '/sysParam'+ url,  // yii 控制器/方法
                    cache: false,
                    data: $("#" + formId).serialize(),
                    error:function(){
                        // alert("数据传输错误");
                    },success: function (data) {
                        layer.closeAll();
                        layer.msg(data.msg);
                        initList();
                    }
                });
            }
            
        }
    });
}

/**
 * 更新参数配置操作
 * @param ele
 */
function updateInfo(ele){
    var _this = $(ele);
    if(_this.attr('data-code') == 'channel'){
        var url = "/channel-update";
        var formId = "channelId";
        var thisIndex = _this.attr('data-index');
        crmSysParamForm.channel = crmSysParamList.res.channelList[parseInt(thisIndex)];
    }
    if(_this.attr('data-code') == 'warranty'){
        var url = "/warranty-update";
        var formId = "warrantyId";
        var thisIndex = _this.attr('data-index');
        crmSysParamForm.warranty = crmSysParamList.res.warrantyList[parseInt(thisIndex)];
    }
    if(_this.attr('data-code') == 'customerLevel'){
        var url = "/customerLevel-update";
        var formId = "customerLevelId";
        var thisIndex = _this.attr('data-index');
        crmSysParamForm.customerLevel = crmSysParamList.res.customerLeveList[parseInt(thisIndex)];
    }
    if(_this.attr('data-code') == 'insurance'){
        var url = "/insurance-update";
        var formId = "insuranceId";
        var thisIndex = _this.attr('data-index');
        crmSysParamForm.insurance = crmSysParamList.res.insuranceList[parseInt(thisIndex)];
    }
    if(_this.attr('data-code') == 'mortgage'){
        var url = "/mortgage-update";
        var formId = "mortgageId";
        var thisIndex = _this.attr('data-index');
        crmSysParamForm.mortgage = crmSysParamList.res.mortgageList[parseInt(thisIndex)];
    }

    layer.open({
        type: 1,
        title:'更新参数',
        area: ['740px', '400px'],
        fixed: false, //不固定
        maxmin: true,
        content: $('#addParamForm'),
        btn:['确定','取消'],
        yes:function(){
            // var formData = $('#addBuyForm').serialize();
            var requiredCode = true;
            $("#" + formId).find('input[required]').each(function(index){
                if($("#" + formId).find('input[required]').eq(index).val() == ''){
                    layer.msg('请输入必填项！');
                    requiredCode = false;
                    return false;
                }
            });
            if (requiredCode) {
                $.ajax({
                    type: "get",      //data 传送数据类型。post 传递
                    contentType:"application/json",
                    dataType: 'json',  // 返回数据的数据类型json
                    url: crmUrl + '/sysParam'+ url,  // yii 控制器/方法
                    cache: false,
                    data: decodeURI($("#" + formId).serialize()),
                    error:function(){
                        // alert("数据传输错误");
                    },success: function (data) {
                        layer.closeAll();
                        layer.msg(data.msg);
                        initList();
                    }
                });
            }
            
        }
    });
}

// 参数列表
function initList(){
    $.ajax({
        type: "get",      //data 传送数据类型。post 传递
        dataType: 'json',  // 返回数据的数据类型json
        url: crmUrl + "/sysParam/paramInfoList",  // yii 控制器/方法
        cache: false,
        error:function(){
            // alert("数据传输错误");
        },success: function (data) {
            if(data.sessionStatus == "timeout"){
                window.location = "../login.jsp"
                    return false;
             }
            crmSysParamList.res = data.result

        }
    });
}
initList();

